<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="收费站" prop="deptId">
        <el-tree-select v-model="queryParams.deptId" :data="deptOptions" :props="{ value: 'id', label: 'label', children: 'children' }" value-key="id"
          class="margin-right" placeholder="请选择收费站" check-strictly clearable />
      </el-form-item>
         <el-form-item label="日期" prop="date">
          <el-date-picker size="small" v-model="queryParams.date" type="date" placeholder="请选择" format="YYYY-MM-DD"  value-format="YYYY-MM-DD" />
        </el-form-item>
        

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:info:add']">新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:info:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange" show-overflow-tooltip   show-summary>
      <el-table-column label="序号" type="index" width="65" align="center" />
          <el-table-column label="日期" align="center" prop="date" width="120" />
      <el-table-column label="收费站名称" align="center" prop="deptName" width="140"  />
   
      <el-table-column label="在岗人数" align="center" prop="">
        <el-table-column label="办公文员数量" align="center" prop="officeClerk" />
        <el-table-column label="票证稽核数量" align="center" prop="ticketVerification" />
        <el-table-column label="ETC人员数量" align="center" prop="etcStaff" />
        <el-table-column label="机电安全人员数量" align="center" prop="electricalMaintenance" />
        <!-- <el-table-column label="监控员数量" align="center" prop="monitorOperator" /> -->
        <el-table-column label="治超员数量" align="center" prop="overloadControl" />
        <el-table-column label="带班长数量" align="center" prop="regularShiftLeader" />
        <el-table-column label="收费人员数量" align="center" prop="tollCollector" />
        <!-- <el-table-column label="小计" align="center" prop="totalStaff" /> -->
      </el-table-column>
      <el-table-column label="请假情况" align="center" prop="">
        <el-table-column label="3天以内" align="center" prop="within3Days" />
        <el-table-column label="4-10天以内" align="center" prop="days4To10" />
        <el-table-column label="11-30天以内" align="center" prop="days11To30" />
        <el-table-column label="30天以外" align="center" prop="over30Days" />
      </el-table-column>
      <el-table-column label="其他情况" align="center" prop="">
        <el-table-column label="离岗创业人数" align="center" prop="leaveForEntrepreneurship" />
        <el-table-column label="停岗人数" align="center" prop="suspended" />
        <el-table-column label="待岗人数" align="center" prop="onHold" />
        <el-table-column label="挂职锻炼" align="center" prop="specialShift" />
        <el-table-column label="支援人数" align="center" prop="support" />
        <el-table-column label="抽调专班人数" align="center" prop="seconded" />
        <el-table-column label="扶贫人数" align="center" prop="helpPoor" />
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:info:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:info:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改人员动态对话框 -->
    <el-dialog :title="title" v-model="open" width="1200px" append-to-body>
      <el-form ref="infoRef" :model="form" :rules="rules" label-width="130px">

        <el-row>
          <el-col :span="12">
            <el-form-item label="收费站名称" prop="deptId">
              <el-tree-select style="width:100%" v-model="form.deptId" :data="deptOptions" :props="{ value: 'id', label: 'label', children: 'children' }"
                value-key="id" placeholder="请选择收费站名称" check-strictly />
            </el-form-item>
          </el-col>
              <el-col :span="12">
            <el-form-item label="日期" prop="date">
            <el-date-picker v-model="form.date" type="date"  style="width: 100%;" format="YYYY-MM-DD"  value-format="YYYY-MM-DD" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="办公文员数量" prop="officeClerk">
              <el-input v-model="form.officeClerk" placeholder="请输入办公文员数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="票证稽核数量" prop="ticketVerification">
              <el-input v-model="form.ticketVerification" placeholder="请输入票证稽核数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ETC人员数量" prop="etcStaff">
              <el-input v-model="form.etcStaff" placeholder="请输入ETC人员数量" />
            </el-form-item> </el-col>
          <el-col :span="12">
            <el-form-item label="机电安全人员数量" prop="electricalMaintenance">
              <el-input v-model="form.electricalMaintenance" placeholder="请输入机电安全人员数量" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12"> <el-form-item label="监控员数量" prop="monitorOperator">
              <el-input v-model="form.monitorOperator" placeholder="请输入监控员数量" />
            </el-form-item></el-col> -->
          <el-col :span="12">
            <el-form-item label="治超员数量" prop="overloadControl">
              <el-input v-model="form.overloadControl" placeholder="请输入治超员数量" />
            </el-form-item> </el-col>
          <el-col :span="12">
            <el-form-item label="带班长数量" prop="regularShiftLeader">
              <el-input v-model="form.regularShiftLeader" placeholder="请输入带班长数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收费人员数量" prop="tollCollector">
              <el-input v-model="form.tollCollector" placeholder="请输入收费人员数量" />
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
            <el-form-item label="小计" prop="totalStaff">
              <el-input v-model="form.totalStaff" placeholder="请输入小计" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">

            <el-form-item label="3天以内" prop="within3Days">
              <el-input v-model="form.within3Days" placeholder="请输入3天以内" />
            </el-form-item>
          </el-col>
          <el-col :span="12">

            <el-form-item label="4-10天以内" prop="days4To10">
              <el-input v-model="form.days4To10" placeholder="请输入4-10天以内" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="11-30天以内" prop="days11To30">
              <el-input v-model="form.days11To30" placeholder="请输入11-30天以内" />
            </el-form-item> </el-col>
          <el-col :span="12">

            <el-form-item label="30天以外" prop="over30Days">
              <el-input v-model="form.over30Days" placeholder="请输入30天以外" />
            </el-form-item>
          </el-col>

          <el-col :span="12"> <el-form-item label="离岗创业人数" prop="leaveForEntrepreneurship">
              <el-input v-model="form.leaveForEntrepreneurship" placeholder="请输入离岗创业人数" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="停岗人数" prop="suspended">
              <el-input v-model="form.suspended" placeholder="请输入停岗人数" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="待岗人数" prop="onHold">
              <el-input v-model="form.onHold" placeholder="请输入待岗人数" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="挂职锻炼" prop="specialShift">
              <el-input v-model="form.specialShift" placeholder="挂职锻炼" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="支援人数" prop="support">
              <el-input v-model="form.support" placeholder="请输入支援人数" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="抽调专班人数" prop="seconded">
              <el-input v-model="form.seconded" placeholder="请输入抽调专班人数" />
            </el-form-item> </el-col>
          <el-col :span="12"> <el-form-item label="扶贫人数" prop="helpPoor">
              <el-input v-model="form.helpPoor" placeholder="请输入扶贫人数" />
            </el-form-item> </el-col>
        </el-row>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Info">
import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser, deptTreeSelect } from "@/api/system/user";
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/coordination/info";
import { getCKInfo } from '@/utils/auth'
import moment from "moment";
const { proxy } = getCurrentInstance();

const infoList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const postOptions = ref([])
const deptOptions = ref([])
const deptId = ref(Number(getCKInfo('deptId')))
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: deptId.value,
    date:""
  },
  rules: {
    deptId: [
      { required: true, message: "收费站名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询人员动态列表 */
function getList() {
  loading.value = true;
  listInfo(queryParams.value).then(response => {
    infoList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 查询岗位结构 */
function getPostTree() {
  getUser().then(response => {
    postOptions.value = response.posts;
  })
};
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}
/** 查询部门下拉树结构 */
function getDeptTree() {
  deptTreeSelect().then(response => {
    deptOptions.value = response.data;
  });
};
// 表单重置
function reset() {
  form.value = {
    id: null,
    deptId: deptId.value,

  };
  proxy.resetForm("infoRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  form.value.date=moment().format('YYYY-MM-DD')
  title.value = "添加人员动态";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getInfo(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改人员动态";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["infoRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addInfo(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除人员动态编号为"' + _ids + '"的数据项？').then(function () {
    return delInfo(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/info/export', {
    ...queryParams.value
  }, `人员动态_${new Date().getTime()}.xlsx`)
}

getList();
// getPostTree()
getDeptTree()
</script>
